<template>
    <div>
        <p v-if="this.$store.state.app.complaintId === ''" align="center">
            <img style="width: 500px;margin-top: 25%" src="@/images/noData.png"/>
        </p>
        <div v-if="this.$store.state.app.complaintId !== ''">
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="发病时间：">
                            <Input v-model="formItem.time" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="主诉内容：">
                            <Input v-model="formItem.content" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="发病情况：">
                            <Input v-model="formItem.situation" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="伴随症状：">
                            <Input v-model="formItem.symptom" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="治疗经过：">
                            <Input v-model="formItem.process" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="目前状况：">
                            <Input v-model="formItem.state" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="使用情况：">
                            <Input v-model="formItem.useSituation" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Row>
                <Col span="12" offset="6">
                    <Form :model="formItem" :label-width="140">
                        <FormItem label="其他情况：">
                            <Input v-model="formItem.otherSituation" type="textarea" :autosize="{minRows: 4,maxRows: 5}" placeholder=""></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            <Card :dis-hover="true" :bordered="false">
                <p slot="title">&nbsp;</p>
                <Row>
                    <Col span="12" offset="6">
                        <p align="right">
                            <Button type="info" @click="save">保存</Button>
                        </p>
                    </Col>
                </Row>
            </Card>
        </div>
    </div>
</template>

<script>
    export default {
        props: {
            id: {
                type: Number,
                default: -1
            },
        },
        data () {
            return {
                baseURL: '/user/complaint',
                selectRows: [],
                showModel: false,
                datas: [],
                formItem: {}
            };
        },
        filters: {
            valueFilter (value) {
                let temp = value
                if (temp === undefined || temp === '') {
                    temp = '无'
                }
                return temp
            }
        },
        methods: {
            save () {
                let url = this.baseURL + '/saveOrUpdate'
                this.$ajax.post(url, this.formItem).then((response) => {
                    let {code, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '已保存')
                        this.refresh()
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            refresh () {
                let url = this.baseURL + '/findById/' + this.$store.state.app.complaintId
                this.$ajax.get(url).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        this.formItem = data
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            init () {
                this.refresh()
            }
        },
        watch: {
        },
        beforeRouteEnter (to, from, next) {
            next(vm => {
                // vm.init()
            })
        }
    }
</script>

<style>
label{
    font-size: 20px;
}
</style>
